home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.004 < prev    next >
Encoding:
Text File  |  1991-01-11  |  12.2 KB  |  273 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIgs
  7. #4:    Changing Graphics Modes in Mid-Application
  8.  
  9. Revised by:    Dave "Dave" Lyons, C.K. Haun & Dan Oliver         January 1991
  10. Written by:    Dan Oliver                                        October 1986
  11.  
  12. This Technical Note discusses how to switch between the two graphics modes, 320
  13. and 640 horizontal resolution, while running an application which usesthe
  14. Window, Control, and Menu Managers.
  15. Changes since May 1990:  Added information about reinstalling fonts after
  16. restarting QuickDraw II.
  17. _____________________________________________________________________________
  18.  
  19. Why Change Resolution?
  20.  
  21. Why not?  There are certain applications where the ability to run in both modes
  22. is essential; most graphics applications fall into this category.Other
  23. applications might switch modes to provide features which their competitors
  24. lack; a financial application might display figures in 640 mode and charts in
  25. 320 mode.  Still other applications may want to give the user the choice.  A
  26. word processor might seem useful only in 640 mode, but what if the user wants to
  27. print greeting cards with pictures?  The user does not need the linelength
  28. provided in 640 mode but does need the added color of 320 mode for the pictures.
  29.  
  30. Let me preach a little.  I have worked on other machines with different graphic
  31. modes and learned some things that might be of use to application programmers.
  32. Many application programmers fight mode switching with either rhetoric or
  33. apathy, then when users expect their software to run in either mode, they become
  34. frustrated when it does not allow switching.  To avoid the problem of
  35. frustrating the user, you can provide mode switching (which is not as hard as
  36. you might think).
  37.  
  38.  
  39. How To Change Modes
  40.  
  41. First, assume you are in an application which is running with a system menu bar,
  42. a few visible windows with scroll bars, and one window with somestandard
  43. controls.  At some point, the user decides to change modes, possibly via a menu
  44. item thoughtfully provided by the application programmer.  Your change mode
  45. handler might look like the following:
  46.  
  47. ;
  48. ; --- This step is necessary if QuickDraw Auxiliary is started ---------------
  49.              _QDAuxShutDown     ;Shut down QDAux first
  50. ; ----------------------------------------------------------------------------
  51.              _QDShutdown        ;Shut down QuickDraw.
  52.                                 ;This will turn graphics off so you will see
  53.                                 ;the text screen for a second (a advertisement
  54.                                 ;might go here).
  55.              lda <mode          ;Variable that holds current resolution.
  56.              eor #$0080         ;Flip the mode bit, $0000 = 320, $0080 = 640.
  57.              sta <mode          ;New value will be used to start the new mode
  58. ;
  59.              pei <QDzpage       ;Pass the direct pages allocated for
  60.                                 ;QuickDraw.
  61.              pei <mode          ;New mode.
  62.              pei <QDwidth       ;0 for screen width; other numbers for
  63.                                 ;printing
  64.              pei <MyID          ;Pass my ID number.
  65.              _QDStartup         ;Restart QuickDraw in the new mode.
  66. ;
  67.              _GrafOff           ;Turn screen off because changing mode
  68.                                 ;may not be pretty.
  69. ; --- This step is necessary if you need QuickDraw Auxiliary  ----------------
  70.              _QDAuxStartUp      ;Start QDAux again
  71. ; ----------------------------------------------------------------------------
  72. ;
  73. ;
  74. ; --- Fix up the cursor for the new mode -------------------------------------
  75. ;
  76.              pea 0              ;Pass minimum cursor X position.
  77.              lda #319           ;Maximum X position for 320 mode.
  78.              ldx <mode          ;320 or 640 mode?
  79.              beq store
  80.              lda #639           ;Maximum X position for 640 mode.
  81. store        pha                ;Pass maximum cursor X position.
  82.              pea 0              ;Pass minimum Y cursor position.
  83.              pea 199            ;Pass maximum Y cursor position.
  84.              _ClampMouse        ;Clamp the cursor to the new screen size.
  85. ;
  86.              _HomeMouse         ;Move the cursor to 0,0 to make sure
  87.                                 ;it is on screen.
  88.              _ShowCursor        ;Make cursor visible.
  89. ;
  90. ;
  91. ; --- Tell tools about the change --------------------------------------------
  92. ;
  93.              _WindNewRes        ;Tell Window Manager about the change.
  94.              _MenuNewRes        ;Tell Menu Manager about the change.
  95.              _CtlNewRes         ;Tell Control Manager about the change.
  96. ;
  97. ;
  98. ; --- Fix the screen to look good --------------------------------------------
  99. ;
  100. ;     Here you might want to change the color of the desktop, windows, menus ;
  101. or controls to look good for the new mode.
  102. ;
  103. ;     See example below.
  104. ;
  105. ; --- Redraw the screen in the new mode --------------------------------------
  106. ;
  107.              pea 0              ;Pass flag to draw entire screen.
  108.              pea 0
  109.              _RefreshDesktop    ;Draw entire screen.
  110. ;
  111.              _GrafOn            ;Now show the new screen.
  112. ;
  113.  
  114. That is not too bad, but I left out the fun part.  Before the RefreshDesktop
  115. there is a section named "Fix up the screen to look good."  This section is
  116. where you might want to put some color into windows, controls, and menus if
  117. you are switching to 320 mode; changing colors is not required, but there are
  118. some things which are.
  119.  
  120. When switching from 640 mode to 320 mode, some windows (both visible and
  121. invisible) might be positioned off the screen in 320 mode.  The first way to
  122. handle this problem is easy for you, the programmer, but not so great for the
  123. user:  close all the windows before changing modes, then position them
  124. correctly when the user opens them in the new mode.  The second way to handle
  125. the problem is to walk the window list and move all the windows, maybe even
  126. change their sizes.  You could double each window's horizontal starting
  127. position and width when switching from 320 mode to 640 mode and halve it when
  128. changing from 640 mode to 320 mode.  The vertical position and height are
  129. okay.  An example of the second method is given below.
  130.  
  131. Windows with vertical scroll bars in the window frame are the same width when
  132. you change modes, so switching from 320 mode to 640 mode results in anarrower
  133. bar while changing from 640 mode to 320 mode produces a wider bar.  The bars
  134. change to the correct size as soon as the user resizes the window, since
  135. SizeWindow deletes the old scroll bars and allocates new ones according tothe
  136. current mode.  If, as suggested above, you resize all the windows after the mode
  137. change and before calling RefreshDesktop, you should be in good shape. If you
  138. choose not the follow this recommendation, you should call SizeWindow for every
  139. window with scroll bars and change the size of each window at least one pixel
  140. since SizeWindow does not do anything if the passed size is not different than
  141. the current size.
  142.  
  143. You should dispose of scroll bars in a window's content region and recreate
  144. them; this is not nice, but very few applications have scroll bars in a window's
  145. content region.
  146.  
  147. You should not resize any open new desk accessory (NDA) windows.  NDAs may be
  148. dependent on screen mode, or their current position, or other such things which
  149. may change with resolution.  To be kind to the NDAs, you should issue a
  150. CloseAllNDAs call.  This call allows the NDAs to go through their normalclose
  151. procedures.  If a user wants an NDA open in the new screen resolution he must
  152. reopen it.  This assures that the NDA always knows its own position and the
  153. current screen resolution.
  154.  
  155. WindNewRes resets the desktop shape and pattern and the Window Manager's icon
  156. font to their defaults for the new mode, so if you changed any of these, you
  157. must add to or subtract from the desktop again and reinitialize to yourcustom
  158. pattern or icon font again.
  159.  
  160. CtlNewRes resets the Control Manager's icon font to the default for the new
  161. mode, so if you changed the Control Manager's icon font, you mustreinitialize to
  162. your icon font again.
  163.  
  164.  
  165. Reinstalling Large Fonts
  166.  
  167. After restarting QuickDraw II, you should call InstallFont again on the
  168. fontsyour application is using.  This causes the Font Manager to
  169. callInflateTextBuffer so that QuickDraw can draw text correctly in large
  170. fontsizes.
  171.  
  172.  
  173. Repositioning and Resizing Windows in the New Mode
  174.  
  175. Here is an example of how to reposition and resize windows in the new mode.
  176.  
  177. ;    QuickDraw and the tools have already been reinitialized in the new mode.
  178. ;    mode = $0000 if in 320 mode, $0080 if in 640 mode.
  179. ;
  180. BoundsRect   equ 8              ;Offsets in port record from QuickDraw document
  181. PortRect     equ 16
  182. ;
  183.              _CloseAllNDAs      ; close all open NDA windows
  184.              pha                ;Space for result.
  185.              pha
  186.              _FrontWindow       ;Start with the top most window, this assumes
  187.              bra enter          ;there are no invisible windows ahead of the
  188.                                 ;active window in the window list.
  189.              ldy #BoundsRect+2
  190.              lda [window],y     ;Get window's starting horizontal position.
  191.              eor #$FFFF         ;Convert to screen coordinate (negate it).
  192.              inc a
  193.              asl a              ;Double it if we're going to 640 mode.
  194.              ldx <mode          ;Going to 320 or 640 mode?
  195.              bne store1         ;Ready if we're going to 640.
  196.              lsr a              ;Otherwise, undo the doubling,
  197.              lsr a              ;and halve the starting horizontal position.
  198.  
  199. store1       pha                ;Pass window's new X starting position.
  200.              ldy #BoundsRect
  201.              lda [window],y     ;Get window's starting vertical position.
  202.              eor #$FFFF         ;Convert to screen coordinate.
  203.              inc a
  204.              pha                ;Pass window's current Y starting position.
  205.              pei <window+2      ;Pass window to move.
  206.              pei <window
  207.              _MoveWindow        ;Move the window to its new position.
  208. ;
  209.              ldy #PortRect+6    ;Get window's current width.
  210.              lda [window],y     ;(This assumes the window's origin is 0,0.)
  211.              asl a              ;Double the window's width if going to 640 mode
  212.              ldx <mode          ;Going to 320 or 640 mode?
  213.              bne store2         ;Ready if we're going to 640.
  214.              lsr a              ;Otherwise, undo the doubling,
  215.              lsr a              ;and halve the window's width.
  216. store2       pha                ;Pass window's new width.
  217.              ldy #PortRect+4
  218.              lda [window],y     ;Get window's height.
  219.              pha                ;Pass window's current height.
  220.              pei <window+2      ;Pass window to resize.
  221.              pei <window
  222.              _SizeWindow        ;Resize the window.
  223. ;
  224.              pha                ;Space for result.
  225.              pha
  226.              pei <window+2      ;Pass pointer to window we just processed.
  227.              pei <window
  228.              _GetNextWindow     ;Get the pointer to the next window.
  229. ;
  230. enter        pla                ;Remember the pointer to this window.
  231.              sta <window
  232.              pla
  233.              sta <window+2
  234. ;
  235.              ora <window        ;Are there any more windows?
  236.              bne loop
  237. ;
  238.  
  239. WindNewRes
  240.  
  241. Generally, WindNewRes does the following:
  242.  
  243.   o  closes its port
  244.   o  opens its port again, now in the new mode
  245.   o  reinitializes the desktop size
  246.   o  chooses the proper icon font for close and zoom boxes
  247.   o  reinitializes the desktop pattern
  248.   o  changes the SCB byte of each window's port to the new mode
  249.   o  recomputes the VisRgn for each window
  250.  
  251. MenuNewRes
  252.  
  253. Generally, MenuNewRes does the following:
  254.  
  255.   o  closes its port
  256.   o  opens its port again, now in the new mode
  257.   o  reinitializes internal parameters, like vertical line width, for the new
  258.      mode
  259.   o  reinitializes the color palette via InitPalette
  260.   o  subtracts the system menu bar from the desktop (this is why you must
  261.      call WindNewRes first)
  262.   o  draws the system menu bar
  263.  
  264. CtlNewRes
  265.  
  266. Generally, CtlNewRes does the following:
  267.  
  268.   o  chooses the proper icon font for radio button, check box, grow box and
  269.      scroll bar arrows
  270.   o  reinitializes internal parameters, like vertical line width, for the new
  271.      mode
  272.  
  273.